package rmi;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

/**
 * 
 * @author LiuHao
 * the launcher of the online book sales system server
 *
 */
public class ServerLauncher {
	
	private CustomerServiceRemote customerServiceRemote;
	private StaffServiceRemote staffServiceRemote;
	
	/**
	 * construction
	 */
	public ServerLauncher() {
		super();
		try {
			customerServiceRemote = new CustomerServiceRemoteImpl();
			staffServiceRemote = new StaffServiceRemoteImpl();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * call the method to launch the server
	 * @return
	 * if the server is successfully launched, return true
	 */
	public boolean launch() {
		try {
			LocateRegistry.createRegistry(1099);
			Naming.rebind("customer_service", customerServiceRemote);
			Naming.rebind("staff_service", staffServiceRemote);
		} catch (Exception e) {
			return false;
		}
		
		return true;
	}

}
